
// Source File Name:   ServiceException.java

package com.sunwayhorizo.health.hl7.common;


import java.io.Serializable;

import java.util.HashMap;
import java.util.Iterator;
import java.util.StringTokenizer;


/* This class has an attribute 'Deprecated' */

public class ServiceException extends Exception
{
    public static interface PathElement
    {

        public abstract String getElementName();

        public abstract int getElementIndex();
    }

    static class PathElementImpl
        implements PathElement
    {

        private String mElementName;
        private int mElementIndex;

        public String getElementName()
        {
            return mElementName;
        }

        public int getElementIndex()
        {
            return mElementIndex;
        }

        public PathElementImpl(String s, int i)
        {
            mElementName = s;
            mElementIndex = i;
        }
    }


    public static final String RCS_ID = "$Header: ServiceException.java 1.0 2008/03/18 00:44:14 ohalaseh noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: ServiceException.java 115.14 2005/03/18 00:44:14 ohalaseh noship $", "com.sunwayhorizo.health.fnd.framework.service");
    private HashMap mParameters;
    public static final String TYPE_PARAM = "TYPE_PARAM";
    public static final String CODE_PARAM = "CODE_PARAM";
    public static final String MESSAGE_PARAM = "MESSAGE_PARAM";
    public static final String PATH_PARAM = "PATH_PARAM";
    public static final String DETAIL_EXCEPTIONS_PARAM = "DETAIL_EXCEPTIONS_PARAM";
    public static final String BUNDLED_EXCEPTIONS_PARAM = "BUNDLED_EXCEPTIONS_PARAM";
    public static final String SEVERE_TYPE = "SEVERE";
    public static final String ERROR_TYPE = "ERROR";
    public static final String WARNING_TYPE = "WARNING";
    public static final String INFO_TYPE = "INFO";
    public static final String CONFIRMATION_TYPE = "CONFIRMATION";

    public ServiceException(String s, String s1, ServiceException aserviceexception[], ServiceException aserviceexception1[])
    {
        mParameters = new HashMap(5);
        mParameters.put("CODE_PARAM", s);
        mParameters.put("TYPE_PARAM", "ERROR");
        mParameters.put("MESSAGE_PARAM", s1);
        mParameters.put("BUNDLED_EXCEPTIONS_PARAM", aserviceexception);
        mParameters.put("DETAIL_EXCEPTIONS_PARAM", aserviceexception1);
    }

    public String getCode()
    {
        return (String)getParameter("CODE_PARAM");
    }

    public String getMessage()
    {
        return (String)getParameter("MESSAGE_PARAM");
    }

    public String getType()
    {
        return (String)getParameter("TYPE_PARAM");
    }

    public void setType(String s)
    {
        setParameter("TYPE_PARAM", s);
    }

/*    public ServiceException[] getDetailExceptions()
    {
        return (ServiceException[])getParameter("DETAIL_EXCEPTIONS_PARAM");
       
    }

    public ServiceException[] getBundledExceptions()
    {
        return (ServiceException[])getParameter("BUNDLED_EXCEPTIONS_PARAM");
    }
*/
    public Serializable getParameter(String s)
    {
        return (Serializable)mParameters.get(s);
    }

    public void setParameter(String s, Serializable serializable)
    {
        mParameters.put(s, serializable);
    }

    public String toString()
    {
        String s = getClass().getName() + "\n";
        for(Iterator iterator = mParameters.keySet().iterator(); iterator.hasNext();)
        {
            Object obj = iterator.next();
            Object obj1 = mParameters.get(obj);
            s = s + obj + "  =  " + obj1 + "\n";
        }

        return s;
    }

    public String getPath()
    {
        return (String)getParameter("PATH_PARAM");
    }

    public void setPath(String s)
    {
        setParameter("PATH_PARAM", s);
    }

    public PathElement[] getPathElements()
    {
        String s = getPath();
        if(s == null)
            return null;
        StringTokenizer stringtokenizer = new StringTokenizer(s, "/");
        int i = stringtokenizer.countTokens();
        PathElement apathelement[] = new PathElement[i];
        for(int j = 0; stringtokenizer.hasMoreElements(); j++)
        {
            String s1 = (String)stringtokenizer.nextElement();
            String s2 = null;
            Object obj = null;
            int k = 0;
            int l = s1.indexOf(46);
            if(l != -1)
            {
                s2 = s1.substring(0, l);
                String s3 = s1.substring(l + 1);
                try
                {
                    k = Integer.parseInt(s3);
                }
                catch(Exception _ex) { }
            } else
            {
                s2 = s1;
            }
            apathelement[j] = new PathElementImpl(s2, k);
        }

        return apathelement;
    }

}
